package com.lzw.breezeNovel.webApp.queue;

import com.lzw.breezeNovel.model.entity.pojo.video.Anime;
import com.lzw.breezeNovel.model.entity.pojo.video.Movie;
import com.lzw.breezeNovel.model.entity.pojo.video.TvSeries;
import lombok.AllArgsConstructor;

import org.jetbrains.annotations.NotNull;

import java.util.Iterator;
/**
 * @author 清风明月
 * @Package com.lzw.breezeNovel.webApp.queue
 * @date 2025/3/19
 * @description 自定义优先队列
 */
@AllArgsConstructor
@SuppressWarnings("all")
public class MergedItem implements Comparable<MergedItem> {
    private final Object item;
    private final Iterator<?> iterator;
    private final double value;

    public MergedItem(Object item, Iterator<?> iterator) {
        this.item = item;
        this.iterator = iterator;
        this.value = calculateValue(item);
    }

    public Object getItem() { return item; }
    public Iterator<?> getIterator() { return iterator; }

    /**
     * @description: 优先队列比较器
     * @param other the object to be compared.
     * @return
     */
    @Override
    public int compareTo(@NotNull MergedItem other) {
        return Double.compare(other.value, this.value); // 降序排列
    }

    /**
     * 计算分值
     * @param obj
     * @return
     */
    public  double calculateValue(Object obj) {
        if (obj instanceof Anime) {
            Anime anime = (Anime) obj;
            return anime.getScore() * 0.6 + anime.getPlayCount() * 0.4;
        } else if (obj instanceof Movie) {
            Movie movie = (Movie) obj;
            return movie.getScore() * 0.6 + movie.getPlayCount() * 0.4;
        } else if (obj instanceof TvSeries) {
            TvSeries tvSeries = (TvSeries) obj;
            return tvSeries.getScore() * 0.6 + tvSeries.getPlayCount() * 0.4;
        }
        return 0;
    }
}
